package main

import "fmt"

// 抽象层
type Fruit interface {
	Show()
}

// 实现层
type Apple struct {
	Fruit
}

func (a *Apple) Show() {
	fmt.Println("我是苹果")
}

type Banana struct {
	Fruit
}

func (b *Banana) Show() {
	fmt.Println("我是香蕉")
}

type Pear struct {
	Fruit
}

func (p *Pear) Show() {
	fmt.Println("我是梨")
}

// 工厂模块
type Factory struct {
}

func (fac *Factory) CreateFruit(kind string) Fruit {
	var fruit Fruit
	if kind == "apple" {
		fruit = new(Apple)
	} else if kind == "banana" {
		fruit = new(Banana)
	} else if kind == "pear" {
		fruit = new(Pear)
	}
	return fruit
}

// 业务逻辑层

func main() {
	factory := new(Factory)
	//fruit
	apple := factory.CreateFruit("apple")
	apple.Show()

	//banana
	banana := factory.CreateFruit("banana")
	banana.Show()

	//pear
	pear := factory.CreateFruit("pear")
	pear.Show()
}
